package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.IProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {
@Autowired
    IProductSpecService productSpecService;

@Operation(summary = "分页查询商品规格参数列表")
    @GetMapping("/list")
    public TableDataInfo list(){
    startPage();
    List<ProductSpec> list=productSpecService.selectProductSpecList();
    return getDataTable(list);
}

@Operation(summary = "新增商品规格参数")
    @PostMapping
    public AjaxResult saveProductSpec(@RequestBody ProductSpec productSpec){
    productSpec.setCreateBy(SecurityUtils.getUsername());
    productSpecService.save(productSpec);
    return AjaxResult.success();
}

@Operation(summary = "根据商品分类id查询商品规格列表")
    @GetMapping("/productSpecList/{categoryId}")
    public AjaxResult productSpecListByCategoryId(@PathVariable("categoryId") Long categoryId){
     List<ProductSpec> list =productSpecService.productSpecListByCategoryId(categoryId);
     return AjaxResult.success(list);
}
}
